#Setup

Before we start, there are a few housekeeping thing to do first. We will need to first download and unzip the data from the drive. the link to the google drive is “https://drive.google.com/drive/folders/1jUS0PNQAg1-2PQfRDs1FQ-3bcJzibWQO?usp=sharing”.

We tried to download the data from the Google drive and the IEA website using direct link and the download file function, but R always say there is a ‘Permission denied’ error because “download had nonzero exit status”error.

Be sure to download the Editied Data folder. When downloading, please put the zip data filed in a folder called “Data” We will also need to download some packages need to do the ploting, data organizing, and reading in the data

list.files(getwd())
## [1] "Edited Data-20230312T064748Z-001.zip"
unzip("Edited Data-20230312T064748Z-001.zip")
list.files(getwd())
## [1] "Edited Data"                         
## [2] "Edited Data-20230312T064748Z-001.zip"
list.files("Edited Data")
##  [1] "2022 World Energy Investment .xlsx"                 
##  [2] "EU Yearly Renewables Generation .csv"               
##  [3] "France Annual Renewable Energy Generation Data.csv" 
##  [4] "Gas Trade Flows _17_02_2023.xls"                    
##  [5] "Germany Annual Renewable Energy Generation Data.csv"
##  [6] "Monthly Energy Statistics.csv"                      
##  [7] "Monthly Gas statistics.csv"                         
##  [8] "Monthly OECD oil statistics.csv"                    
##  [9] "Monthly Oil Statistics.xlsx"                        
## [10] "Reliance on Russian imports.xlsx"                   
## [11] "World Energy Balances Highlights 2022.xlsx"
list.of.packages <- c("ggplot2", "readxl","tidyr","magrittr","dplyr")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

library(ggplot2)
library(readxl)
library(tidyr)
library(magrittr)
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:tidyr':
## 
##     extract
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout

Introduction

This project will focus on exploring trends in energy investment,prices, production and consumption in Europe, with particular focus on the time since the start of the Russia- Ukraine War that started in 2022. Our Analysis will focus on the energy production, import, and export of Russia, and countries of focus within the EU, specifically Germany and France.

Other countries, such as China, was originally considered, however, there were issues in obtaining time relevant data, which is data from 2021 to the end of 2022. Indeed, when collecting data for this project, finding time relevant data for many topics were challenging, and data are usually more available for Economic Co-operation and Development (OECD) countries than non-OECD ones.

Data

We collected those data from IEA or Ember Climate.Org. Most files are organized in a Tidy Data format, but there are some data, such as the “Monthly Oil Statistics”,“Reliance on Russian Imports” ,and “Gas Trade Flows”, that require some reorganizing. there are some datasets, like “World Energy Balance Highlights”, that were particularly difficult to reorganize into a tidy data format, so we use a package call tidyr to help the process. As we looked through the other excel files, we also singled out the countries of interest and put their data in a seperate data sheet in excel to make them easier to work with.

Loading all the data into data frames

Excel Files

2022 World Energy Investment

Source: IEA

This data include the world and regional investment data for supply (fossil fuels, renewables, electricity networks, other) and end-use (energy efficiency, renewables and other). For this project we will only be looking at Europe and the World

World_Energy_Investment <- as.data.frame(read_xlsx("Edited Data/2022 World Energy Investment .xlsx", sheet = "World"))

Europe_Energy_Investment <- as.data.frame(read_xlsx("Edited Data/2022 World Energy Investment .xlsx", sheet = "Europe"))

Monthly Oil (Energy Price) Statistics

Source:IEA

This data set contains the monthly end-user total prices for transport fuels in selected countries, based on the IEA Energy Prices database. This data only contains price information for Diesel, Gasoline and Domestic Heating Oil. There is a more comprehensive dataset available on IEA that includes Natural Gas, but it requires a subscription. We will use the three fuel type to for common price variation trends

Monthly_Oil_Statistics <- as.data.frame(read_xlsx("Edited Data/Monthly Oil Statistics.xlsx", sheet = "Table",skip = 5))

OPEC Reliance on Russia Fuel

Source: IEA

This data set containes the most up-to-date information on the reliance of OECD countries on oil imports from Russia. When we go over the data on excel, we created two seperate sheet for France and Germany. While this process can be achieved via indexing, we created the sheet because it was easy to do.

OPEC_Reliance_on_Russian_imports <- as.data.frame(read_xlsx("Edited Data/Reliance on Russian imports.xlsx", sheet = "Reliance_Fuel"))


France_Reliance_on_Russian_imports <- as.data.frame(read_xlsx("Edited Data/Reliance on Russian imports.xlsx", sheet = "French Reliance on Russia"))


Germany_Reliance_on_Russian_imports <- as.data.frame(read_xlsx("Edited Data/Reliance on Russian imports.xlsx", sheet = "Germnay Reliance on Russia"))

Gas Trade Flow

Source: IEA

This data contains information on European countries and their natural gas networks, including pipline and gas flow at entry point. For this file, only Germany is included in the analysis, because the data shows France doesn’t have a direct gas link with Russia. Similarly, we also created a sperate sheet for just Germany.

Germany_Gas_Trade_Flows <- as.data.frame(read_xls("Edited Data/Gas Trade Flows _17_02_2023.xls", sheet = "To Germany"))

World_Energy_Balance

Source IEA

This data contains the energy balance data for all 38 OECD countries and 11 IEA Association countries as well as relevant aggregates and complete time series from 1971 wherever possible. We created two seperate sheets for France and Germany for ease of use

World_Energy_Balance <- as.data.frame(read_xlsx("Edited Data/World Energy Balances Highlights 2022.xlsx",skip=1, sheet = "TimeSeries_1971-2021"))

France_Energy_Balance <- as.data.frame(read_xlsx("Edited Data/World Energy Balances Highlights 2022.xlsx", sheet = "France"))

Germany_Energy_Balance<- as.data.frame(read_xlsx("Edited Data/World Energy Balances Highlights 2022.xlsx", sheet = "Germany"))

csv file

EU and Countries of Interest Renewables Generation

Source:Ember Climate.Org

EU_Yearly_Renewables_Generation <- as.data.frame(read.csv("Edited Data/EU Yearly Renewables Generation .csv"))

France_Annual_Renewable_Energy_Generation<- as.data.frame(read.csv("Edited Data/France Annual Renewable Energy Generation Data.csv"))

Germany_Annual_Renewable_Energy_Generation_Data <- as.data.frame(read.csv("Edited Data/Germany Annual Renewable Energy Generation Data.csv"))

Monthly Energy Statistics

Source:IEA

This Dataset contains the monthly updates for electricity production and trade data for OECD Member Countries and electricity production data for a selection of other economies.

Monthly_Energy_Statistics <- as.data.frame(read.csv("Edited Data/Monthly Energy Statistics.csv",skip = 8))

Monthly Gas Statistics

Source: IEA

This data provides data on natural gas production, consumption, total imports and total exports for all OECD Member countries

Monthly_Gas_statistics <- as.data.frame(read.csv("Edited Data/Monthly Gas statistics.csv"))

Monthly OECD Oil Statistics

Source:IEA

The data contains information for oil production for all OECD member countries, and imports, exports, refinery outputs and net deliveries for major product categories for all OECD regions.

Monthly_OECD_oil_statistics <-as.data.frame(read.csv("Edited Data/Monthly OECD oil statistics.csv"))

Tidying up the data

Since some data are not in the tidy format, we are going to use tidyr package to make them into one. (We didn’t come accross the package until the second day of data wrangling, and we applied it to data that are cumbersome to tidy up by hand)

There are 5 data frames that need to be tidied up, including all the Energy Balance Data, Monthly Oil Statistics Data, and OPEC Reliance on Russia Import.

For the reliance on Russia data frames, we also multiplied the original number by 100 to get the percentage, and we also rounded the number to two decimal places for easy reading

# Energy balance Data

France_Energy_Balance <- France_Energy_Balance %>% gather(Year, Energy, 4:54)


Germany_Energy_Balance <- Germany_Energy_Balance %>% gather(Year, Energy, 4:54)


World_Energy_Balance <- World_Energy_Balance %>% gather(Year, Energy, 7:57)

# Monthly Oil Statistics

Monthly_Oil_Statistics <- Monthly_Oil_Statistics %>% gather(Year, Price, 5:101)

#Reliance on Russia Import

OPEC_Reliance_on_Russian_imports <- OPEC_Reliance_on_Russian_imports %>% gather(Year, Reliance, 3:34)


France_Reliance_on_Russian_imports$Reliance <- France_Reliance_on_Russian_imports$Reliance*100
France_Reliance_on_Russian_imports$Reliance <- format(round(France_Reliance_on_Russian_imports$Reliance, 2), nsmall = 2)
colnames(France_Reliance_on_Russian_imports) <- c("YEAR","COUNTRY","PRODUCT","Reliance %")


Germany_Reliance_on_Russian_imports$Reliance <- Germany_Reliance_on_Russian_imports$Reliance*100
colnames(Germany_Reliance_on_Russian_imports) <- c("YEAR","COUNTRY","PRODUCT","Reliance %")


OPEC_Reliance_on_Russian_imports$Reliance <- as.numeric(OPEC_Reliance_on_Russian_imports$Reliance,na.rm=TRUE)*100
## Warning: NAs introduced by coercion
colnames(OPEC_Reliance_on_Russian_imports) <- c("YEAR","COUNTRY","PRODUCT","Reliance %")

Deal with NA Values

Some data also contain characters that symbolizes NA value in columns and cells. This make later analysis difficult. We will now deal with them by setting these characters in to NA

World_Energy_Balance[World_Energy_Balance ==".."] <- NA
Germany_Energy_Balance[Germany_Energy_Balance ==".."] <- NA
France_Energy_Balance[France_Energy_Balance ==".."] <- NA
France_Energy_Balance[France_Energy_Balance =="c"] <- NA
# c stands for confidential

1 Context

2 What are the EU {Countries of Interest( France and Germany)} and Russia’s energy import and export prior to the Russian Invasion of Ukraine?

5 What is the energy profile of France and Germany, and what are the trend in renewable energy production compared to fossil fuels since the Ukrainian war?

For this question, we will be looking at the energy profile of the European Union, France ,and Germany. We will focus particularly on the renewable and fossil fuel energy production trends, and how these trends changed through the years with detailed focus from 2019 to 2023. To answer this question, We will use the EU, Germany, and France Annual Renewable Energy Generation Data from EMBER Climate.Org.

Edit Energy Types

levels(as.factor(EU_Yearly_Renewables_Generation$variable))
##  [1] "Bioenergy"        "Clean"            "Coal"             "Fossil"          
##  [5] "Gas"              "Hydro"            "Nuclear"          "Other Fossil"    
##  [9] "Other Renewables" "Solar"            "Wind"             "Wind and solar"
levels(as.factor(France_Annual_Renewable_Energy_Generation$variable))
##  [1] "Bioenergy"        "Clean"            "Coal"             "Fossil"          
##  [5] "Gas"              "Hydro"            "Nuclear"          "Other Fossil"    
##  [9] "Other Renewables" "Solar"            "Wind"             "Wind and solar"
levels(as.factor(Germany_Annual_Renewable_Energy_Generation_Data$variable))
##  [1] "Bioenergy"        "Clean"            "Coal"             "Fossil"          
##  [5] "Gas"              "Hydro"            "Nuclear"          "Other Fossil"    
##  [9] "Other Renewables" "Solar"            "Wind"             "Wind and solar"

The first thing we need to do is to determine how many different energy sources are contained in these data sets, and by converting the variable (energy type) column into factors, we can see see that the data set contains 12 different classifications energy. However, if we look more carefully, we can see that “Clean”,“Wind and Solar”, and “Fossil” are just the sum of different combinations of other energy types. Therefore, we need to first remove the rows containing these three classifications from the data.

EU_Yearly_Renewables_Generation <- EU_Yearly_Renewables_Generation[EU_Yearly_Renewables_Generation$variable != "Fossil" & EU_Yearly_Renewables_Generation$variable != "Clean" & EU_Yearly_Renewables_Generation$variable != "Wind and solar" ,]

EU_Yearly_Renewables_Generation$variable <- factor(EU_Yearly_Renewables_Generation$variable,levels = c("Wind","Solar","Hydro","Bioenergy","Other Renewables","Nuclear","Gas","Coal","Other Fossil"))

France_Annual_Renewable_Energy_Generation <- France_Annual_Renewable_Energy_Generation[France_Annual_Renewable_Energy_Generation$variable != "Fossil" & France_Annual_Renewable_Energy_Generation$variable != "Clean" & France_Annual_Renewable_Energy_Generation$variable != "Wind and solar" ,]

Additionally, for ease of ploting, we would like to rearrange the levels of factors by their types. In this case, we rearrange the energy types by classifying them as renewables, nuclear and Fossil fuels.

Rearrange Energy type

France_Annual_Renewable_Energy_Generation$variable <- factor(EU_Yearly_Renewables_Generation$variable,levels = c("Wind","Solar","Hydro","Bioenergy","Other Renewables","Nuclear","Gas","Coal","Other Fossil"))

Germany_Annual_Renewable_Energy_Generation_Data <- Germany_Annual_Renewable_Energy_Generation_Data[Germany_Annual_Renewable_Energy_Generation_Data$variable != "Fossil" & Germany_Annual_Renewable_Energy_Generation_Data$variable != "Clean" & Germany_Annual_Renewable_Energy_Generation_Data$variable != "Wind and solar" ,]

Germany_Annual_Renewable_Energy_Generation_Data$variable <- factor(Germany_Annual_Renewable_Energy_Generation_Data$variable,levels = c("Wind","Solar","Hydro","Bioenergy","Other Renewables","Nuclear","Gas","Coal","Other Fossil"))

We also want to single out the period of 2019 to 2022 to see this period with more detail

EU_Yearly_Renewables_Generation_2019_2022 <- EU_Yearly_Renewables_Generation[(EU_Yearly_Renewables_Generation$year > 2018),]

France_Annual_Renewable_Energy_Generation_2019_2022 <- France_Annual_Renewable_Energy_Generation[(France_Annual_Renewable_Energy_Generation$year > 2018),]

Germany_Annual_Renewable_Energy_Generation_Data_2019_2022 <- Germany_Annual_Renewable_Energy_Generation_Data[(Germany_Annual_Renewable_Energy_Generation_Data$year > 2018),]

After cleaning up the data, we can start to plot the energy profile and trends of EU, France and Germany. We think the stacked area plot would be most useful in this case to show how different energy types changed over the years and how dominant they are in a country’s energy profile.

The European Union

par( mfrow= c(1,2) )

EU_Energy_Production_Profile <- ggplot(EU_Yearly_Renewables_Generation, aes(x=EU_Yearly_Renewables_Generation$year, y=EU_Yearly_Renewables_Generation$generation_twh, fill=EU_Yearly_Renewables_Generation$variable)) + 
    geom_area() +theme_bw(base_size=8)+theme(strip.background =element_rect(fill="white"))+ labs(y="EU Energy Generation by Source",x= "Year",title = "EU Energy Production Profile (2000 to 2022)")+ guides(fill=guide_legend(title="EU Energy Production Type")) + scale_fill_manual(values = c("skyblue1","orange1","dodgerblue","chartreuse4","green3","violet","gray","grey20","seashell4"))



EU_Energy_Production_Profile_2019_2022 <- ggplot(EU_Yearly_Renewables_Generation_2019_2022, aes(x=EU_Yearly_Renewables_Generation_2019_2022$year, y=EU_Yearly_Renewables_Generation_2019_2022$generation_twh, fill=EU_Yearly_Renewables_Generation_2019_2022$variable)) + 
    geom_area()+theme_bw(base_size=8)+theme(strip.background =element_rect(fill="white"))+labs(y="EU Energy Generation by Source (Terawatt hour)",x= "Year",title = "EU Energy Production Profile (2019 to 2022)")+ guides(fill=guide_legend(title="EU Energy Production Type"))+scale_fill_manual(values = c("skyblue1","orange1","dodgerblue","chartreuse4","green3","violet","gray","grey20","seashell4"))

EU_Energy_Production_Profile

EU_Energy_Production_Profile_2019_2022

When looking at the energy production profile, we can see that the total energy production has increased. Bio, wind and solar energy are emerging as prominent renewable energy types, with wind particularly gaining attraction. Other renewables like hydropower had already established a foothold in the EU’s energy profile as a notable renewable energy source.

Additionally, nuclear power is very prominent in the EU, however its use has declined overtime. In terms of fossil fuels, natural gas uses has increased overtime, coupled with a decline in the use of coal and other forms of fossil fuels. Notably, coal use in the EU decline from 2000 to 2020, when it experienced a rebound, but even so the overall use of coal is still lower than the start of the century.

France

par( mfrow= c(1,2) )

France_Energy_Production_Profile <- ggplot(France_Annual_Renewable_Energy_Generation, aes(x=France_Annual_Renewable_Energy_Generation$year, y=France_Annual_Renewable_Energy_Generation$generation_twh, fill=France_Annual_Renewable_Energy_Generation$variable)) + 
    geom_area()+theme_bw(base_size=8)+theme(strip.background =element_rect(fill="white"))+ labs(y="EU Energy Generation by Source",x= "Year",title = "France Energy Production Profile (2000 to 2022)")+ guides(fill=guide_legend(title="France Energy Production Type"))+ scale_fill_manual(values = c("skyblue1","orange1","dodgerblue","chartreuse4","green3","violet","gray","grey20","seashell4"))

France_Energy_Production_Profile_2019_2022 <- ggplot(France_Annual_Renewable_Energy_Generation_2019_2022, aes(x=France_Annual_Renewable_Energy_Generation_2019_2022$year, y=France_Annual_Renewable_Energy_Generation_2019_2022$generation_twh, fill=France_Annual_Renewable_Energy_Generation_2019_2022$variable)) + 
    geom_area()+theme_bw(base_size=8)+theme(strip.background =element_rect(fill="white"))+labs(y="France Energy Generation by Source (Terawatt hour)",x= "Year",title = "France Energy Production Profile (2019 to 2022)")+ guides(fill=guide_legend(title="France Energy Production Type"))+scale_fill_manual(values = c("skyblue1","orange1","dodgerblue","chartreuse4","green3","violet","gray","grey20","seashell4"))

plot(France_Energy_Production_Profile)

plot(France_Energy_Production_Profile_2019_2022)

We are interesting in seeing how the dominance of nuclear energy has changed between 2000 to 2022, so we calculated the percentages of nuclear power as a percentage of total energy production in 2000 and 2022.

#France Nuclear Energy Percentage in 2000
France_Annual_Renewable_Energy_Generation[(France_Annual_Renewable_Energy_Generation$year==2000)&(France_Annual_Renewable_Energy_Generation$variable=="Nuclear"),]
sum(France_Annual_Renewable_Energy_Generation[which(France_Annual_Renewable_Energy_Generation$year==2000),4])
## [1] 533.6
415.16/533.6
## [1] 0.778036
#France Nuclear Energy Percentage in 2022
France_Annual_Renewable_Energy_Generation[(France_Annual_Renewable_Energy_Generation$year==2022)&(France_Annual_Renewable_Energy_Generation$variable=="Nuclear"),]
sum(France_Annual_Renewable_Energy_Generation[which(France_Annual_Renewable_Energy_Generation$year==2022),4])
## [1] 469.48
297.2/469.48
## [1] 0.6330408

For France, the most interesting finding is how dominant the use of nuclear power is. At the start of the century, France was producing more than 415.16 twh of nuclear power, accounting for 77.8% of France’s total energy production. However, this reliance diminished with time, and since 2019, France’s Nuclear power generation dropped below 400 twh, and in 2022, nuclear power only accounts for 63.3% of the energy generated in France.

As for the other energy type, France has laged behind overall EU’s adoption of both wind and solar energy, with both only starting to gain attraction between 2005 to 2010. Meanwhile, hydropower continues to play a major role in energy production, but its output has reduced.

For fossil fuels, the graph shows that coal use has been diminishing for sometime, decreasing from 27 twh in 2000 to only 4.4 twh in 2022. if the trend continues, it is likly going to be phased out. On the other hand, Gas use nearly quadrupled in the same time period, rising from 11.51 twh to 43 twh.

One dicernable trend when looking at both the time from 2000 to 2023 and from 2019 to 2023, is that the France's total energy production has dropped. Looking at the time frame from 2019 to 2023, it appears that the major contributor of this drop is the decrease in nuclear power generation.

Germany

par( mfrow= c(1,2) )
Germany_Energy_Production_Profile <- ggplot(Germany_Annual_Renewable_Energy_Generation_Data, aes(x=Germany_Annual_Renewable_Energy_Generation_Data$year, y=Germany_Annual_Renewable_Energy_Generation_Data$generation_twh, fill=Germany_Annual_Renewable_Energy_Generation_Data$variable)) + 
    geom_area()+theme_bw(base_size=8)+theme(strip.background =element_rect(fill="white"))+ labs(y="EU Energy Generation by Source",x= "Year",title = "Germany Energy Production Profile (2000 to 2022)")+ guides(fill=guide_legend(title="Germany Energy Production Type"))+ scale_fill_manual(values = c("skyblue1","orange1","dodgerblue","chartreuse4","green3","violet","gray","grey20","seashell4"))

Germany_Energy_Production_Profile_2019_2022 <- ggplot(Germany_Annual_Renewable_Energy_Generation_Data_2019_2022, aes(x=Germany_Annual_Renewable_Energy_Generation_Data_2019_2022$year, y=Germany_Annual_Renewable_Energy_Generation_Data_2019_2022$generation_twh, fill=Germany_Annual_Renewable_Energy_Generation_Data_2019_2022$variable)) + 
    geom_area()+theme_bw(base_size=8)+theme(strip.background =element_rect(fill="white"))+labs(y="Germany Energy Generation by Source (Terawatt hour) ",x= "Year",title = "Germany Energy Production Profile (2019 to 2022)")+ guides(fill=guide_legend(title="Germany Energy Production Type"))+scale_fill_manual(values = c("skyblue1","orange1","dodgerblue","chartreuse4","green3","violet","gray","grey20","seashell4"))

plot(Germany_Energy_Production_Profile)

plot(Germany_Energy_Production_Profile_2019_2022)

We also calculated the change in coal use in Germany as a percentage of total energy production

#Germany Coal Energy Percentage in 2000

Germany_Annual_Renewable_Energy_Generation_Data[(Germany_Annual_Renewable_Energy_Generation_Data$year==2000)&(Germany_Annual_Renewable_Energy_Generation_Data$variable=="Coal"),]
sum(Germany_Annual_Renewable_Energy_Generation_Data[which(Germany_Annual_Renewable_Energy_Generation_Data$year==2000),4])
## [1] 572.3
296.68/572.3
## [1] 0.5183994
#Germany Coa Energy Percentage in 2020
Germany_Annual_Renewable_Energy_Generation_Data[(France_Annual_Renewable_Energy_Generation$year==2020)&(Germany_Annual_Renewable_Energy_Generation_Data$variable=="Coal"),]
sum(Germany_Annual_Renewable_Energy_Generation_Data[which(Germany_Annual_Renewable_Energy_Generation_Data$year==2020),4])
## [1] 567.26
134.6/567.26
## [1] 0.237281

Comparing to France, Germany’s energy composition is much more diverse, how it is very notable that Germany relied heavily on fossil fuel, especially coal at the start of the century. indeed, when looking at the data, Germany produced nearly 300twh of energy using coal at 2000, more than half of Germany’s total produced energy that year. However, Germany’s use of coal declined considerably since then, reaching its lowest output at 2020 (23.73%). Meanwhile ,the decline of coal use prompts the increased usable of other energy sources. For instance, the use of natural gas nearly doubled between 2000 to 2023.
Another notable feature of Germany’s energy production profile is its wide use of wind energy compared to France and the EU as a whole, and how wind energy took off after 2010. Similar growth in adoption is also true for solar and bioenergy as well. Hydropower generation, however seems to remain the same overtime. Germany’s use of nuclear power is an interesting case, as we can see that tis share in total energy production has shrunk considerably. it is interesting to see that in both France and Germany, there is a trend to shift away from nuclear power. Perhaps this is due to public concerns over its safety, along with its environmental and ethical issues? When narrowing down to just the 2019 to 2022 time period, we were expecting to find a drop in natural gas production due to the Russia-Ukrain War, and the sabotage of Nord Stream Pipline that connected Russia and Germany. However, the data shows that the use of natural gas in Germany was stable. instead, the most notable changes happened to coal and nuclear power

6 What is the trend of energy prices for France and Germany?

Finally, we are interested in looking at how the energy prices might have changed through the years and impacted by the Russia-Ukrain War. to answer this question, we found the data called “Monthly Oil Statistics” from IEA. Other data sets were considered as well, such as the “Monthly Gas Statistics”, but the data contained are only focused on the time between 2020 to 2022, and the values contained are unrelated to Gas prices. Despite Gas being the most featured fossil fuel after the sabotage of Nord Stream Pipeline, Oil is still part of the energy picture. For instance, Germany halted its importation of Russian Oil in Jan 2023. Therefore, looking into the trends of oil prices can still be very interesting.

The first thing to do is to change the decimal places for price to just 2, and change the time format to dates rather than characters.

Then we shall extract the data related to Germany and France. Apart from country, we also need to extract the data based the product and the currency standard. The data uses both US Dollar and National Currency (The Euro) as measurement. For this case, we will measure monetary value based on US Dollar.

Change Dates, Decimal Places, and Extract Data on France and Germany

The dates contained in this data set are in numerical values so we need to change them int dates

#Change Time
#The dates contained in this data set are in numerical values so we need to change them int dates
Monthly_Oil_Statistics$Year <- as.numeric(Monthly_Oil_Statistics$Year)
Monthly_Oil_Statistics$Year <- as.numeric(Monthly_Oil_Statistics$Year)
Monthly_Oil_Statistics$Year <- as.Date(Monthly_Oil_Statistics$Year,
    origin = "1899-12-30")

#Change Decimal Places
#We also want to shorten up the decimal places to make the numbers more readable
Monthly_Oil_Statistics$Price <- as.numeric(Monthly_Oil_Statistics$Price,na.rm=TRUE)
## Warning: NAs introduced by coercion
Monthly_Oil_Statistics$Price <- format(round(Monthly_Oil_Statistics$Price, 2), nsmall = 2)

#We finally want to extract data only related to France and Germany Based on different oil products
France_Gasoline_Price <- Monthly_Oil_Statistics[(Monthly_Oil_Statistics$COUNTRY=="France")&(Monthly_Oil_Statistics$UNIT=="US dollars")&(Monthly_Oil_Statistics$PRODUCT=="Gasoline (unit/litre)"),]
France_Diesel_Price <- Monthly_Oil_Statistics[(Monthly_Oil_Statistics$COUNTRY=="France")&(Monthly_Oil_Statistics$UNIT=="US dollars")&(Monthly_Oil_Statistics$PRODUCT=="Diesel (unit/litre)"),]
France_Heating_Oil_Price <- Monthly_Oil_Statistics[(Monthly_Oil_Statistics$COUNTRY=="France")&(Monthly_Oil_Statistics$UNIT=="US dollars")&(Monthly_Oil_Statistics$PRODUCT=="Domestic heating oil (unit/litre)"),]

Germany_Gasoline_Price <- Monthly_Oil_Statistics[(Monthly_Oil_Statistics$COUNTRY=="Germany")&(Monthly_Oil_Statistics$UNIT=="US dollars")&(Monthly_Oil_Statistics$PRODUCT=="Gasoline (unit/litre)"),]
Germany_Diesel_Price <- Monthly_Oil_Statistics[(Monthly_Oil_Statistics$COUNTRY=="Germany")&(Monthly_Oil_Statistics$UNIT=="US dollars")&(Monthly_Oil_Statistics$PRODUCT=="Diesel (unit/litre)"),]
Germany_Heating_Oil_Price <- Monthly_Oil_Statistics[(Monthly_Oil_Statistics$COUNTRY=="Germany")&(Monthly_Oil_Statistics$UNIT=="US dollars")&(Monthly_Oil_Statistics$PRODUCT=="Domestic heating oil (unit/litre)"),]

France and Germany Energy Price Plots

par( mfrow= c(1,2))
#we start with plotting for France
France_Energy_Prices <- plot_ly(x = France_Gasoline_Price$Year, y =France_Gasoline_Price$Price,name = "Gasoline", type = 'scatter', mode = 'markers+lines')
France_Energy_Prices <-  add_trace(France_Energy_Prices, x = France_Diesel_Price$Year, y = France_Diesel_Price$Price,name = "Diesel", type="scatter", mode="markers+lines")
France_Energy_Prices <-  add_trace(France_Energy_Prices, x = France_Heating_Oil_Price$Year, y = France_Heating_Oil_Price$Price,name = "Heating Oil", type="scatter", mode="markers+lines")
France_Energy_Prices <- France_Energy_Prices %>% layout(title = 'France Gasoline, Diesel,and Heating Oil Price (2015-2023)',
         xaxis = list(
      rangeselector = list(
        buttons = list(
          list(
            count = 3,
            label = "3 mo",
            step = "month",
            stepmode = "backward"),
          list(
            count = 6,
            label = "6 mo",
            step = "month",
            stepmode = "backward"),
          list(
            count = 1,
            label = "1 yr",
            step = "year",
            stepmode = "backward"),
          list(
            count = 1,
            label = "YTD",
            step = "year",
            stepmode = "todate"),
          list(step = "all"))),

      rangeslider = list(type = "date")),
         yaxis = list (title = 'Prices'))
France_Energy_Prices
htmlwidgets::saveWidget(as_widget(France_Energy_Prices), "France_Energy_Prices.html")


#We then move on to Germany using similar methods
Germany_Energy_Prices <- plot_ly(x = Germany_Gasoline_Price$Year, y =Germany_Gasoline_Price$Price,name = "Gasoline", type = 'scatter', mode = 'markers+lines')
Germany_Energy_Prices <-  add_trace(Germany_Energy_Prices, x = Germany_Diesel_Price$Year, y = Germany_Diesel_Price$Price,name = "Diesel", type="scatter", mode="markers+lines")
Germany_Energy_Prices <-  add_trace(Germany_Energy_Prices, x = Germany_Heating_Oil_Price$Year, y = Germany_Heating_Oil_Price$Price,name = "Heating Oil", type="scatter", mode="markers+lines")
Germany_Energy_Prices <- Germany_Energy_Prices %>% layout(title = 'Germany Gasoline, Diesel,and Heating Oil Price (2015-2023)',
         xaxis = list(
      rangeselector = list(
        buttons = list(
          list(
            count = 3,
            label = "3 mo",
            step = "month",
            stepmode = "backward"),
          list(
            count = 6,
            label = "6 mo",
            step = "month",
            stepmode = "backward"),
          list(
            count = 1,
            label = "1 yr",
            step = "year",
            stepmode = "backward"),
          list(
            count = 1,
            label = "YTD",
            step = "year",
            stepmode = "todate"),
          list(step = "all"))),

      rangeslider = list(type = "date")),
         yaxis = list (title = 'Prices'))
Germany_Energy_Prices
htmlwidgets::saveWidget(as_widget(France_Energy_Prices), "Germany_Energy_Prices.html")

We can see that for both France and Germany, the various energy sources depicted in this graph are all increasing overtime. For France, Gasoline prices rose by 36%, Diesel increased by 53%, and Domestic Heating Oil price increased the most by 83.75% between 2015 to 2023. Comparable increases are experienced in Germany as well, 27% for Gasoline, 48% for diesel, and 92.6% for heating oil.

All three energy prices rose and fall in a similar trend, and there are two very interesting observations. Firstly, there was a sharp decrease in all three energy price from Jan to Apr of 2020, and followed by a gradual increase of price in all three energy types. Then between Dec 2021 and March 2022, the prices of all three experienced a rapid rise, particularly Heating Oil which increased by 56% for France and 83.33% for Germany (However, the price actually increased by 158.8% for Germany at its peak comparing to original prices in 2015).

What is very interesting is that the Russia-Ukrain War started on Feb 24,2022, which coincided with the biggest jump in energy price for Heating oil from Feb to Mar 2022 (Increase of 32.8% for France, and 54.39% for Germany). ???

Conclusion